#ifndef STACKEDDIALOG_H
#define STACKEDDIALOG_H

#include <QDialog>
#include "ui_stackeddialog.h"
#include "recordinfo.h"
#include "alertinfo.h"
#include "addrecord.h"
#include "managealert.h"
#include "report.h"
#include "expenserecordlist.h"
#include "incomerecordlist.h"
#include "alertlist.h"
#include "operationprocessor.h"

// change table to include relevant information i.e. price, date, name
using namespace std;
class StackedDialog : public QDialog , public Ui::StackedDialog
{
    Q_OBJECT
private:
    vector<Record> expenseResults;
    vector<Record> incomeResults;
    ExpenseRecordList expenseRecords;
    IncomeRecordList incomeRecords;
    Alert alert;
    AlertList alertList;
    RecordInfo *recordInfo;
    AlertInfo *alertInfo;
    AddRecord *addRecord;
    ManageAlert *manageAlert;
    Report *report;
    PropertyTree tree;
    OperationProcessor processor;
    Operation op;
    void reloadExpenseList();
    void reloadIncomeList();
    double balance;
    double income;
    double expense;
    double balancealert;
    string searchInput;
    string searchOptionField;
    string searchOptionType;
    string searchOptionCategory;
    string accountname;
    string reportOptionType;
    string reportOptionDate;
    double reportOptionToPrice;
    double reportOptionFromPrice;
    vector<QString> reportOptionExpenseCategory;
    vector<QString> reportOptionIncomeCategory;
    int timer;

public:
    StackedDialog(QWidget *parent = 0);
    Record searchRecords(QString, vector<Record>);
    Record searchRecords(QString, ExpenseRecordList);
    Record searchRecords(QString, IncomeRecordList);
    int currentTimeInSeconds();
    double calculateBalance();
    void deleteIncome(string);
    void deleteExpense(string);
    void timerEvent(QTimerEvent *);
    void checkBalance();
    void checkAlert();

signals:
    void setVisibleBox(bool);
private slots:
    void on_accountName_textChanged(QString);
    void on_addIncomeRecordButton_clicked();
    void on_addExpenseRecordButton_clicked();
    void on_incomeUndoButton_clicked();
    void on_expenseUndoButton_clicked();

    void on_createReportButton_clicked();

    void on_manageAlertButton_clicked();

    void updateAlertList(AlertList);
    void on_searchButton_clicked();

    void setField(QString);
    void setType(QString);
    void setCategory(QString);
    void addExpenseCategory(string);
    void addIncomeCategory(string);

    void openExpenseRecord(QListWidgetItem*);
    void openIncomeRecord(QListWidgetItem*);

    void enableWindow();
    void saveToXML();
    void loadFromXML();
    void setIncomeChecked(QListWidgetItem*);
    void setExpenseChecked(QListWidgetItem*);
    void priceConstraint();
    void dateConstraint();
    void saveIncome(QDateTime, string, string, string, double);
    void saveExpense(QDateTime, string, string, string, double);
    //void modifyExpense(string nameID, string id, QDateTime newdatetime, string newname,                       string newinfo, string newcategory, double newamount);
    void modifyExpense(Record oldRecord, Record newRecord);
    //void modifyIncome(string nameID, string id, QDateTime newdatetime, string newname,                      string newinfo, string newcategory, double newamount);
    void modifyIncome(Record oldRecord, Record newRecord);
    void removeIncome(string);
    void removeExpense(string);
    void removeIncomeCategory(string);
    void removeExpenseCategory(string);
    void updateReportType(QString);
    void updateReportCategoryAll(bool);
    void check();
};

#endif // STACKEDDIALOG_H
